import pymysql

def add_one():
    # 连接数据库
    con = pymysql.connect(host='localhost',port=3306,user='root',password='root',db='test',charset='utf8')
    # 创建游标
    cur = con.cursor()

    #sql语句
    sql='insert into emp values (0,%s,%s,%s)'
    args = ['Tom',3000,10]
    # 执行sql语句
    cur.execute(sql,args)
    con.commit()
    #关闭游标和连接
    cur.close()
    con.close()

def add_many():
    # 连接数据库
    con = pymysql.connect(host='localhost', port=3306, user='root', password='root', db='test', charset='utf8')
    # 创建游标
    cur = con.cursor()

    # sql语句
    sql = 'insert into emp values (0,%s,%s,%s)'
    args = [['name1', 3000, 10], ['name2', 4000, 20], ['name3', 5000, 30]]
    # 执行sql语句
    cur.executemany(sql, args)
    con.commit()
    # 关闭游标和连接
    cur.close()
    con.close()

if __name__ == '__main__':
    add_many()